package xdu.lz.stage2_design_pattern.chapter8_guarded_suspension_pattern;

import java.util.Random;

public class ClientThread extends Thread {
    private final RequestQueue queue;

    private static final Random random = new Random(System.currentTimeMillis());

    private final String sendValue;

    public ClientThread(RequestQueue queue, String sendValue) {
        this.queue = queue;
        this.sendValue = sendValue;
    }

    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println("client -> request "+sendValue);
            queue.putRequest(new Request(sendValue));
            try {
                Thread.sleep(random.nextInt(10));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
